namespace Part3_IndividuleAssignment2.Migrations
{
    using System;
    using System.Data.Entity;
    using System.Data.Entity.Migrations;
    using System.Linq;
    using Part3_IndividuleAssignment2.Models;

    internal sealed class Configuration : DbMigrationsConfiguration<Part3_IndividuleAssignment2.Models.NewsSystemEntities>
    {
        public Configuration()
        {
            AutomaticMigrationsEnabled = false;
        }

        protected override void Seed(Part3_IndividuleAssignment2.Models.NewsSystemEntities context)
        {
            Province bc = new Province { ProvinceName = "British Columbia" };
            Province ab = new Province { ProvinceName = "Alberta" };
            Province on = new Province { ProvinceName = "Ontario" };

            City vancouver = new City { CityName = "Vancouver", Province = bc };
            City victoria = new City { CityName = "Victoria", Province = bc };
            City kelowna = new City { CityName = "Prince George", Province = bc };
            City calgary = new City { CityName = "Calgary", Province = ab };
            City edmonton = new City { CityName = "Edmonton", Province = ab };
            City redDeer = new City { CityName = "Red Deer", Province = ab };
            City toronto = new City { CityName = "Toronto ", Province = on };
            City ottawa = new City { CityName = "Ottawa ", Province = on };
            City mississauga = new City { CityName = "Mississauga", Province = on };

            Account testAccount = new Account { FirstName = "Jerry", LastName = "Cai", Email = "fake@email.com", City = vancouver };

            NewsItem testNewsItem = new NewsItem { Account = testAccount, Content = "This is test news." };

            context.Provinces.AddOrUpdate(p => p.ProvinceName, on, bc, ab);

            context.Cities.AddOrUpdate(c => c.CityName, vancouver, victoria, kelowna, calgary, edmonton,
                redDeer, toronto, ottawa, mississauga);

            context.Accounts.AddOrUpdate(a => a.Email, testAccount);
            context.NewsItems.AddOrUpdate(n => n.Content, testNewsItem);

        }
    }
}
